package com.example.myapplication;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class SqliteHelper extends SQLiteOpenHelper {

  public static final String DATABASE_NAME = "NoteDatabase.db";
  public static final String USER_TABLE = "users";
  public static final String NOTE_TABLE = "notes";
  public static final String DELETE_TABLE = "deletenotes";

  private static final int DATABASE_VERSION = 1;
  private SQLiteDatabase database;

  public SqliteHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
    database = getWritableDatabase();
  }
  @Override public void onCreate(SQLiteDatabase db) {
    //在第一次创建时创建数据库表
    db.execSQL(
        "create table IF NOT EXISTS Users(UID INTEGER PRIMARY KEY AUTOINCREMENT ,userAccount varchar(20) not null UNIQUE,userPassword varchar(20) not null, nickName varchar(20) not null,State int(1) DEFAULT 1,Administrator int(1) DEFAULT 0,RegisterTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP)");
    //db.execSQL(
    //    "CREATE TABLE IF NOT EXISTS Notes(noteID INTEGER PRIMARY KEY AUTOINCREMENT,authorName VARCHAR(20) not null ,authorAccount VARCHAR(20) not null ,title VARCHAR(20),createtime TIMESTAMP not null DEFAULT CURRENT_TIMESTAMP,updatetime TIMESTAMP not null DEFAULT CURRENT_TIMESTAMP,content LONGTEXT)");
    db.execSQL("CREATE TABLE IF NOT EXISTS Notes(noteID INTEGER PRIMARY KEY AUTOINCREMENT,authorName VARCHAR(20) not null ,authorAccount VARCHAR(20) not null ,title VARCHAR(20),createtime TIMESTAMP not null DEFAULT CURRENT_TIMESTAMP,updatetime TIMESTAMP not null DEFAULT CURRENT_TIMESTAMP,content LONGTEXT,favour INTEGER DEFAULT 0)");
  }

  @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

  }
  public void DeleteTable() {
    database.execSQL("DROP TABLE IF EXISTS Notes");

  }


}
